/************************************************************
   Copyright 2008 Abhinav Pobbati

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*************************************************************/

#include "HkPrerequisites.h"

#include "Havok4Xna/Common/Base/Math/HkQuaternion.h"
#include "Havok4Xna/Common/Base/Math/HkVector4.h"
#include "Havok4Xna/Common/Base/Math/HkMatrix3.h"

namespace Havok4Xna {
	HkQuaternion::HkQuaternion() {
		_setThis(new hkQuaternion(), true);
	}
	HkQuaternion::HkQuaternion(float ix, float iy, float iz, float r) {
		_setThis(new hkQuaternion(ix, iy, iz, r), true);
	}
	HkQuaternion::HkQuaternion(HkRotation ^r) {
		_setThis(new hkQuaternion(r->_ref()), true);
	}
	HkQuaternion::HkQuaternion(HkVector4 ^axis, float angle) {
		_setThis(new hkQuaternion(axis->_ref(), angle), true);
	}
	void HkQuaternion::Set(float ix, float iy, float iz, float r) {
		_this()->set(ix, iy, iz, r);
	}
	void HkQuaternion::SetIdentity() {
		_this()->setIdentity();
	}
	void HkQuaternion::SetInverse(HkQuaternion ^q) {
		_this()->setInverse(q->_ref());
	}
	void HkQuaternion::Normalize() {
		_this()->normalize();
	}
	void HkQuaternion::SetMul(float r, HkQuaternion ^q) {
		_this()->setMul(r, q->_ref());
	}
	void HkQuaternion::SetMul(HkQuaternion ^a, HkQuaternion ^b) {
		_this()->setMul(a->_ref(), b->_ref());
	}
	void HkQuaternion::AddMul(float r, HkQuaternion ^q) {
		_this()->addMul(r, q->_ref());
	}
	void HkQuaternion::Mul(HkQuaternion ^q) {
		_this()->mul(q->_ref());
	}
	void HkQuaternion::SetMulInverse(HkQuaternion ^a, HkQuaternion ^b) {
		_this()->setMulInverse(a->_ref(), b->_ref());
	}
	void HkQuaternion::SetInverseMul(HkQuaternion ^a, HkQuaternion ^b) {
		_this()->setInverseMul(a->_ref(), b->_ref());
	}
	void HkQuaternion::SetShortestRotation(HkVector4 ^from, HkVector4 ^to) {
		_this()->setShortestRotation(from->_ref(), to->_ref());
	}
	void HkQuaternion::SetAxisAngle(HkVector4 ^axis, float angle) {
		_this()->setAxisAngle(axis->_ref(), angle);
	}
	void HkQuaternion::Set(HkRotation ^r) {
		_this()->set(r->_ref());
	}
	void HkQuaternion::SetAndNormalize(HkRotation ^r) {
		_this()->setAndNormalize(r->_ref());
	}
	void HkQuaternion::RemoveAxisComponent(HkVector4 ^axis) {
		_this()->removeAxisComponent(axis->_ref());
	}
	void HkQuaternion::SetSlerp(HkQuaternion ^q0, HkQuaternion ^q1, float t) {
		_this()->setSlerp(q0->_ref(), q1->_ref(), t);
	}
	bool HkQuaternion::HasValidAxis() {
		return _this()->hasValidAxis();
	}
	IMPL_COMPLEX_PROPERTY_GETTERSETTER(
		HkQuaternion, Imag, HkVector4, hkQuaternion,
		getImag, setImag, hkVector4)
	HkVector4 ^HkQuaternion::Axis::get() {
		if(!_this()->hasValidAxis())
			return nullptr;
		if(_Axis == nullptr) {
			_Axis = gcnew HkVector4(new hkVector4(), true);
		}
		_this()->getAxis(_Axis->_ref());
		return _Axis;
	}
	float HkQuaternion::IX::get() {
		return _ref()(0);
	}
	float HkQuaternion::IY::get() {
		return _ref()(1);
	}
	float HkQuaternion::IZ::get() {
		return _ref()(2);
	}
	float HkQuaternion::IW::get() {
		return _ref()(3);
	}
	float HkQuaternion::Angle::get() {
		return _this()->getAngle();
	}

	IMPL_SIMPLE_PROPERTY_GETTERSETTER(float, Real, getReal, setReal, HkQuaternion);
}
